﻿using PoemGame.Domain.PlayerAggregate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace PoemGame.Repository.Simple
{
    public class PlayerRepository : IPlayerRepository
    {
        private List<Player> _players;

        public PlayerRepository()
        {
            _players = new List<Player>();
        }
        public Task<Guid> AddAsync(Player player)
        {
            _players.Add(player);
            return Task.FromResult(player.Id);
        }

        public Task<IEnumerable<Player>> GetAllAsync()
        {
            return Task.FromResult(_players as IEnumerable<Player>);
        }

        public Task<IEnumerable<Player>> GetByConditionAsync(Expression<Func<Player, bool>> predicate)
        {
            return Task.FromResult(_players.AsQueryable().Where(predicate).ToList() as IEnumerable<Player>);
        }

        public Task<Player?> GetPlayerByIdAsync(Guid id)
        {
            return Task.FromResult(_players.Find(o => o.Id  == id));
        }

        public Task<Player?> GetPlayerByUserNameAsync(string username)
        {
            return Task.FromResult(_players.Find(o => o.UserName == username));
        }

        public Task RemoveAsync(Player player)
        {
            _players.Remove(player);
            return Task.CompletedTask;
        }

        public Task UpdateAsync(Player player)
        {
            return Task.CompletedTask;
        }
    }
}
